# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pidgin
pkgver=2.14.10
pkgrel=0
pkgdesc="Graphical, multi-protocol instant messaging client"
url="https://pidgin.im/"
arch="all"
license="GPL-2.0-or-later"
makedepends="gtk+2.0-dev intltool libsm-dev startup-notification-dev gtkspell-dev
	libxml2-dev libidn-dev gnutls-dev avahi-dev
	cyrus-sasl-dev ncurses-dev nss-dev
	libgnt-dev
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang
	libpurple-bonjour:_bonjour
	libpurple-xmpp:_xmpp
	finch libpurple
	"
#source="https://bitbucket.org/pidgin/main/downloads/$pkgname-$pkgver.tar.bz2"
source="https://downloads.sourceforge.net/project/pidgin/Pidgin/$pkgver/pidgin-$pkgver.tar.gz"
options="!check"

# secfixes:
#   2.14.9-r0:
#     - CVE-2022-26491

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-avahi \
		--disable-dbus \
		--disable-doxygen \
		--disable-gnutls \
		--disable-meanwhile \
		--disable-nm \
		--disable-perl \
		--disable-schemas-install \
		--disable-screensaver \
		--disable-tcl \
		--disable-vv \
		--disable-gstreamer \
		--disable-gstreamer-interfaces \
		--disable-farstream \
		--disable-gevolution \
		--enable-cyrus-sasl \
		--enable-nss
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

finch() {
	pkgdesc="text-based multi-protocol instant messaging client"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/finch "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/lib/finch "$subpkgdir"/usr/lib/
}

libpurple() {
	pkgdesc="multi-protocol instant messaging library"
	mkdir -p "$subpkgdir"/usr/lib "$subpkgdir"/usr/share/sounds
	mv "$pkgdir"/usr/lib/*purple* "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/share/purple "$pkgdir"/usr/share/sounds \
		"$subpkgdir"/usr/share/
}

_mv_purple() {
	pkgdesc="$1"
	shift
	mkdir -p "$subpkgdir"/usr/lib/purple-2/
	local i
	for i; do
		mv "$pkgdir"/usr/lib/purple-2/$i.* \
			"$subpkgdir"/usr/lib/purple-2/
	done
}

_bonjour() {
	_mv_purple "bonjour plugin for libpurple" libbonjour
}

_xmpp() {
	_mv_purple "Jabber/XMPP plugins for libpurple" libxmpp libjabber
}

sha512sums="
dfaf990d4f5efc6781899b793b3bd8f79c1239286746f379b3dd03ffc12c7ce4be234dee8094b6a0da360e58867e7fddcc6be2389a10f1b59e5f21fa30e11398  pidgin-2.14.10.tar.gz
"
